package connection

import (
	"api-gateway-core/common"
	"api-gateway-core/mapping"
	"context"
	"dubbo.apache.org/dubbo-go/v3/config/generic"
	hessian "github.com/apache/dubbo-go-hessian2"
)

type DubboConnection struct {
	genericService *generic.GenericService
}

func NewDubboConnection(configuration *common.Configuration, statement *mapping.HttpStatement) (*DubboConnection, error) {
	genericService, err := configuration.GetReference(statement)
	return &DubboConnection{genericService}, err
}

func (this *DubboConnection) Execute(ctx context.Context, methodName string, types []string, args []hessian.Object) (any, error) {
	return this.genericService.Invoke(ctx, methodName, types, args)
}
